package xyz.xtt.asset.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;

import xyz.xtt.asset.constants.AssetCache;
import xyz.xtt.asset.entity.TblAssetsType;
import xyz.xtt.asset.mapper.TblAssetsTypeMapper;
import xyz.xtt.asset.response.QueryAssetTypeResponse;
import xyz.xtt.asset.service.ITblAssetsTypeService;
import xyz.xtt.asset.vo.AssetTypeResponseVo;
import xyz.xtt.common.objects.DozerUtil;
import xyz.xtt.common.starter.cache.CacheManager;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-10-17
 */
@Service
public class TblAssetsTypeServiceImpl extends ServiceImpl<TblAssetsTypeMapper, TblAssetsType> implements ITblAssetsTypeService {
	@Autowired
	private CacheManager cacheManager;

	@Override
	public List<QueryAssetTypeResponse> type() {
		List<TblAssetsType> list = cacheManager.cacheList(() -> baseMapper.selectList(Wrappers.emptyWrapper()), AssetCache.TBL_ASSET_TYPE);
		return DozerUtil.transforList(list, QueryAssetTypeResponse.class);
	}

	@Override
	public List<AssetTypeResponseVo> search(String typePlatform) {
		MPJLambdaWrapper<TblAssetsType> query = JoinWrappers
				.lambda(TblAssetsType.class)
				.selectAs(TblAssetsType::getType, AssetTypeResponseVo::getName)
				.selectAs(TblAssetsType::getTypeCode, AssetTypeResponseVo::getCode)
				.eq(TblAssetsType::getTypePlatform, typePlatform);
		return query.list(AssetTypeResponseVo.class);
	}
}
